<template>
    <div class="user">
        <basic-container>
            <avue-crud
                    v-model="form"
                    v-model:page="page"
                    v-model:search="searchForm"
                    :permission="getPermission"
                    v-bind="bindVal"
                    v-on="onEvent"
                    :option="option"
                    :data="tableData"
                    :before-open="beforeOpen"
            >
                <template #menu-left="{size}">
                    <el-button type="primary" @click="importShowHandle()">导入</el-button>
                    <el-button type="primary" @click="exportHandle()">导出</el-button>
                </template>
              <template #menu="scope">
                <el-button link type="primary" size="small" icon="el-icon-plus" @click="tracks(scope.row)">跟踪</el-button>
              </template>
            </avue-crud>

        </basic-container>

        <import-upload :base-url="pageConfig.url" :model-name="pageConfig.name" v-model="importDialogVisible"  ></import-upload>


      <el-dialog title="跟踪" v-if="showTracks"   v-model="showTracks"  width="50%" >
        <avue-crud
            v-model="formItem"
            v-model:page="itemPage"
            v-model:search="searchFormItem"
            @search-change="searchItemChange"
            :option="optionItem"
            :data="tableDataItem"
            @row-save="handleItemSave"
            @row-del="handleItemDel"
            @size-change="itemSizeChange"
            @current-change="itemCurrentChange"
        >
        </avue-crud>
      </el-dialog>
    </div>
</template>

<script>
    import curdMixin from '@/framework-core/mixins/crud';
    import {tableOption} from "./index";
    import ImportUpload from "@/framework-core/components/upload/index.vue";
    import TableForm from "@/framework-admin/views/oa/oadoc/form.vue";
    import {delCore, pageCore, saveCore} from "@/framework-core/api/core/api";
    import website from "@/framework-core/config/website";


    export default {
        name: "oa_task",
        mixins: [curdMixin],
        components: {TableForm, ImportUpload},
        data() {
          return {
            showTracks: false,
            pageConfig: {name: "任务分配", "url": "/oa/oaTask"},
            pageConfigItem:{name:"任务跟踪","url":"/oa/oaTaskTrack"},
            searchForm: {},
            loading: false,
            taskId:"",
            form: {},
            option: tableOption,
            formItem:{},
            tableDataItem:[],
            searchFormItem:{},
            itemPage: {
              total: 0, // 总页数
              currentPage: 1, // 当前页数
              pageSize: website.pageSize // 每页显示多少条
            },
            optionItem:{
              "border": true,
              "index": true,
              "indexLabel": "#",
              "stripe": true,
              "menuAlign": "center",
              "align": "center",
              "searchMenuSpan": 6,
              searchEnter:true,
              selection: true,
              editBtn:false,
              grid: window.isMobile,
              gridSpan: 24,
              menuWidth: 140,
              "column": [
                {
                  "type": "input",
                  "label": "反馈内容",
                  "prop": "track",
                  "overHidden": false,
                  "rules": [{
                    required:true,
                    message: '反馈内容不能为空',
                    trigger: 'blur'
                  }],
                  'search':  true,
                  "span": 12
                },
                {
                  "type": "date",
                  "label": "创建时间",
                  "prop": "createTime",
                  "overHidden": false,
                  "width":"200",
                  display:false,
                  format: 'YYYY-MM-DD HH:mm:ss',
                  valueFormat: 'YYYY-MM-DD HH:mm:ss',
                  "span": 12
                }
              ]
            }
          };
        },
        computed: {
            ...mapState({
                permissions: (state) =>state.user.permission,
            })

        },
        created() {
            this.myinitOptionDict();
            this.init();
        },
        methods: {
          init() {
          },
          tracks(row) {
            this.taskId = row.id;
            this.searchFormItem.taskId = this.taskId;
            this.showTracks = true;
            this.getItemPage();
          },
          getPermission: function (key, row, index) {
            return this.getCommPermission(key, row, index);
          },
          getItemPage() {
            this.showTracks = true;
            pageCore(this.pageConfigItem.url,
                this.getParamItemSearch()
            ).then(response => {
              this.tableDataItem = response.data.data.records;
              this.itemPage.total = response.data.data.total;
            });
          },
          searchItemChange(form, done) {
            this.searchFormItem = form;
            this.itemPage.currentPage = 1;
            this.getItemPage();
            if(done){
              done();
            }
          },

          getParamItemSearch() {
            var obj = {
              pageNum: this.itemPage.currentPage,
              pageSize: this.itemPage.pageSize
            };
            obj.entity = this.searchFormItem;
            obj.entity.taskId = this.taskId;
            return obj;
          },

          handleItemSave: function (row, done) {
            row.taskId = this.taskId;
            saveCore(this.pageConfigItem.url, row).then(() => {
              this.$message.success("添加成功");
              this.getItemPage();
              if(done){    done();}
            });
          },
          handleItemDel: function (row) {
            var $that = this;
            this.$confirm('是否确认删除数据为"' + row.name + '"的数据项?', "警告", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            })
                .then(function () {
                  return delCore($that.pageConfigItem.url, row);
                })
                .then(() => {
                  this.getItemPage();
                  this.$message.success("删除成功");
                })
                .catch(function () {
                });
          },
          itemSizeChange(pageSize) {
            this.itemPage.pageSize = pageSize;
            this.getItemPage();
          },
          itemCurrentChange(current) {
            this.itemPage.currentPage = current;
            this.getItemPage();
          },

        }
    };
</script>
<style lang="scss">

</style>
